<?php

namespace app\admin\model\inventory;

use think\Model;

class Wmskcview extends Model
{
    // 表名
    protected $name = 'wms_kc_view';

    //配置模型小数点格式化（去0补0）
    //要格式化的 字段=>方法
    protected $type = [
        'quantity'=>'quantity',
        'store_quantity' => 'quantity',
        'cur_quantity'=>'quantity',
        'iQuantity'=>'quantity',
        'fqty' => 'quantity',
        'fCoefficient' => 'quantity'
    ];

    // 追加属性
    protected $append = [
        'now_kc'
    ];

    //现有库存
    public function getNowKcAttr($value, $data)
    {
        //$data['number']
        //只扣掉待复核销售出库的单
        $nowkc = db('temporary')->where([
            'order_list' => ['IN',[15]],
            'inv_id' => $data['inv_id'],
            'shelves_id' => $data['shelves_id'],
            'cBatch' => $data['cBatch'],
            'status' => 0 //待复核
        ])
        ->sum('quantity');

        return $nowkc;
    }
}
